package com.mayuanfei.controller;

import com.mayuanfei.pojo.UserInfo;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

/**
 * 获得参数值
 *
 * @author 老马
 * @date 2023-03-27 14:54
 */
@RestController
public class GetDataController {

    @RequestMapping("/getParamByRequest")
    public String getParam(HttpServletRequest request) {
        String userid = request.getParameter("userid");
        String password = request.getParameter("password");
        return "userid="+userid+", password="+password;
    }

    @RequestMapping("/getParamByName")
    public String getParam2(String userid, @RequestParam("pwd") String password){
        return "userid="+userid+", password="+password;
    }

    @RequestMapping("/getParamByPojo")
    public String getParam3(UserInfo userInfo) {
        return userInfo.toString();
    }

    @RequestMapping("/getParamByPojoWithList")
    public String getParam4(UserInfo userInfo) {
        return userInfo.toString();
    }

    @RequestMapping("/getParamByPojoWithMap")
    public String getParam5(UserInfo userInfo) {
        return userInfo.toString();
    }

    @RequestMapping("/getParamByPojoWithJson")
    public String getParam6(@RequestBody UserInfo userInfo) {
        return userInfo.toString();
    }

    @RequestMapping(value = "/getGetParamByPojoWithCN", method = RequestMethod.GET, produces = "text/plain;charset=utf-8")
    public String getParam7(UserInfo userInfo) {
        System.out.println(userInfo);
        return userInfo.toString();
    }

    @RequestMapping(value = "/getPostParamByPojoWithCN", method = RequestMethod.POST)
    public String getParam8(String userid, String username) {
        System.out.println(userid+","+username);
        return userid+","+username;
    }

    @RequestMapping(value = "/getPostParamByPojoWithCN2", method = RequestMethod.POST)
    public String getParam9(@RequestBody UserInfo userInfo) {
        System.out.println(userInfo.toString());
        return userInfo.toString();
    }

    @RequestMapping(value = "/getPostParamByPojoWithCN3", method = RequestMethod.POST)
    public String getParam10(UserInfo userInfo) {
        System.out.println(userInfo.toString());
        return userInfo.toString();
    }
}